package com.yyge.web.servlet.<----MIN---->;

import cn.hutool.crypto.digest.BCrypt;
import com.yyge.dao.Impl._____DaoImpl;
import com.yyge.entity.BaseEntity;
import com.yyge.entity.Userinfo;
import com.yyge.util.JwtUtile;
import com.yyge.util.ServletUtil;
import com.yyge.vo.R;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 删除用户的API
 */

@WebServlet("/delete/")
public class Delete extends HttpServlet {

    /**
     * 删除用户的API
     * @param req 必须传入ID
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BaseEntity baseEntity = ServletUtil.fetchDataFromRequest(req,_____.class);
        Map<String, Object> params = baseEntity.getParams();
        _____ targrt = (_____) baseEntity;

        _____DaoImpl impl=new _____DaoImpl();
        Map<String, Object> att = targrt.getParams();
        System.out.println(targrt);
        R r=new R();
        if(targrt.getId() == null){
            r=R.fail("非法传参!");
            ServletUtil.writeResult2Client(resp,r);
            return;
        }

        //删除之前验证Token
        _____ <----MIN----> = impl.findbyId(targrt.getId());
        if(!JwtUtile.tokenVerify(<----MIN---->.getToken())){
            r=R.fail("错误！您无权操作!");
            ServletUtil.writeResult2Client(resp,r);
        }


        int remove = impl.remove(targrt.getId());
        if (remove>0){
            r=R.fail("删除成功!");
            ServletUtil.writeResult2Client(resp,r);
        }else{
            r=R.fail("删除失败!不存在的对象");
            ServletUtil.writeResult2Client(resp,r);
        }

    }
}
